<?php
class Swearwords extends Controller {

    function Swearwords(){
        parent::Controller();
        $this->load->helper(array('form','tiap_helper','html'));
        $this->load->library('form_validation'); 
        $this->load->model(array('User_model','Comments_model','Crime_report_model'));
        if (!$this->User_model->is_admin_user()){ 
			redirect('admin');
		}    
    }
    
    function index(){
    	$data = array();
    	$order_by = $this->uri->segment(4);
    	$region = $this->uri->segment(5);
    	$search = $this->uri->segment(6);
		$page = (int)$this->uri->segment(7);
		$submit_button = $this->input->post('submit');
		if(!empty($submit_button)){
			$order_by = $this->input->post('sorting');
			$region = $this->input->post('province');
			$search = $this->input->post('search');
			$search = ($search == ''|| $search == 'Search...')?'none':$search;
			//echo $search;
		}
		//echo $order_by;
		$order_by = ($order_by == '')?'desc_date':$order_by;
		$region = ($region == '')?'0':$region;
		$page = ($page == '')?0:$page;
		$search = ($search == '')?'none':$search;
		//$per_page = (int)$this->uri->segment(7);
		$twitter_show = ($twitter_show == '')?'yes':$twitter_show;
    	$per_page = 30;
    	$data['total_crime'] = $this->Crime_report_model->total_crime_report($region,$search);
		// pagination start
		$this->load->library('pagination');
		$config['base_url'] = site_url('admin/crime_report/index/'.$order_by.'/'.$region.'/'.$search);
		$config['total_rows'] = $data['total_crime'];
		$config['per_page'] = $per_page;
	
		$config['uri_segment'] = 7;

		$this->pagination->initialize($config); 

		$data['pagination'] =  $this->pagination->create_links();
		//pagination end
    	$data['order_by'] = $order_by;
    	$data['region'] = $region;	
    	
    	$data['crime_report_list'] = $this->Crime_report_model->get_crime_report($per_page,$page,$order_by,$search,$region,'yes');
    	
		$this->load->view(TEMPLATE_NAME.'/admin/swearwords/main',$data);
    }
   
}
